<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<!DOCTYPE html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

    <jsp:include page="${pageContext.request.contextPath}/WEB-INF/views/screen/admin/resource.jsp"/>
    <link href="${pageContext.request.contextPath}/js/jquery-easyui-1.5.4.1/themes/default/easyui.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/js/jquery-easyui-1.5.4.1/themes/icon.css" rel="stylesheet">
    <script src="${pageContext.request.contextPath}/js/jquery-easyui-1.5.4.1/jquery.easyui.min.js"
            charset="utf-8"></script>
</head>

<body>

<div class="layui-collapse">
    <div class="layui-colla-item">
        <h2 class="layui-colla-title">新增|编辑</h2>
        <div class="layui-colla-content layui-show">
            <form id="editForm" class="layui-form layui-form-pane" action="">
                <input type="hidden" id="id" name="id" value="${data.id}"/>
                <div class="layui-form-item">
                    <label class="layui-form-label">角色名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="roleName" lay-verify="required" placeholder="请输入角色名称" autocomplete="off"
                               class="layui-input" value="${data.roleName}">
                    </div>
                </div>

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">描述</label>
                    <div class="layui-input-block">
                        <textarea name="note" placeholder="角色描述" class="layui-textarea">${data.note}</textarea>
                    </div>
                </div>
                <%--<div style="border: 1px solid #A4BED4; width:230px;height:200px;margin-left: 105px ;overflow: auto; ">--%>
                <%----%>
                <%--</div>--%>
                <div class="layui-form-item">
                    <label class="layui-form-label">权限</label>
                    <div class="layui-input-block"
                         style="border: 1px solid #A4BED4;height:200px;padding-left: 105px ;overflow: auto; ">
                        <ul id="menu-tree" class="easyui-tree" checkbox="true" url="/admin/sysMenu/getMenuTree.htm">

                        </ul>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <c:choose>
                            <c:when test="${type!='look'}">
                                <button class="layui-btn" lay-submit lay-filter="save">提交</button>
                            </c:when>
                        </c:choose>
                        <a href="/admin/sysRole/index.htm" class="layui-btn">返回</a>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

</body>
<script src="${pageContext.request.contextPath}/js/ux/sysRole/sysRole.js"></script>
</html>
<script>
    $(function () {
        setTimeout('A()', 500); //延迟1秒


    })
    function A() {
        if('${data.id}'!=""){
            $.ajax({
                type: "post",
                url: "/admin/sysRole/getMenuIdsAndBtnIds",
                data: {'roleId':'${data.id}'},
                dataType: "json",
                success: function (result) {
                    if (result.success == true) {
                        var btnIds = result.btnIds;
                        var menuIds = result.menuIds;
                        $.each(btnIds, function (i, id) {
                            setTreeValue("btn_" + id);
                        })

                        $.each(menuIds, function (i, id) {
                            setTreeValue("menu_" + id);
                        });
                    } else {
                        layer.msg(result.msg, {
                            icon: 5,
                            offset: '150px'
                        });
                    }
                }
            });
        }
    }

    function setTreeValue(id) {
        var node = $("#menu-tree").tree("find", id);
        console.log(node)
        if (node && node.target) {
            //判断是否选择或者半选状态
            if ($(node.target).find(".tree-checkbox0")[0]) {
                $("#menu-tree").tree('check', node.target);
            }
        }
    }

</script>


